package com.wlcorp.forcazamis.web.action.baseinfo;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import com.wlcorp.forcazamis.business.baseinfo.ISampleTypeService;
import com.wlcorp.forcazamis.domain.baseinfo.SampleType;
import com.wlcorp.forcazamis.sys.util.AppConstant;
import com.wlcorp.forcazamis.sys.util.ContextUtil;
import com.wlcorp.forcazamis.sys.util.WebUtil;

public class SampleTypeAction extends DispatchAction {
	public ActionForward getSampleTypeList(ActionMapping mapping,ActionForm form,
			HttpServletRequest request,HttpServletResponse response){
		List<SampleType> sampleTypeList = ContextUtil.getInstance().getSampleTypeService().getSampleTypeList(null);
		request.setAttribute("sampleTypeList",sampleTypeList);
		return mapping.findForward("list");
	}
	
	public ActionForward getSampleType(ActionMapping mapping,ActionForm form,
			HttpServletRequest request,HttpServletResponse response){
		SampleType sampleType = new SampleType();
		WebUtil.setRequestToObject(request,sampleType);
		sampleType = ContextUtil.getInstance().getSampleTypeService().getSampleTypeById(sampleType.getSampleTypeId());
		if(null == sampleType){
			sampleType = new SampleType();
		}
		request.setAttribute("sampleType",sampleType);
		return mapping.findForward("modify");
	}
	
	public ActionForward modifySampleType(ActionMapping mapping,ActionForm form,
			HttpServletRequest request,HttpServletResponse response){
		SampleType sampleType = new SampleType();
		WebUtil.setRequestToObject(request,sampleType);
		ContextUtil.getInstance().getSampleTypeService().saveSampleType(sampleType);
		if(AppConstant.BASE_BEAN_STATUS_ERROR == sampleType.getStatus()){
			WebUtil.setAlertMessage(request,sampleType.getMsg());
		}else{
			WebUtil.setAlertMessage(request,"操作成功！");
		}
		
		request.setAttribute("sampleType",sampleType);
		return mapping.findForward("modify");
	}
	
	public ActionForward deleteSampleType(ActionMapping mapping,ActionForm form,
			HttpServletRequest request,HttpServletResponse response){
		SampleType sampleType = new SampleType();
		WebUtil.setRequestToObject(request,sampleType);
		ISampleTypeService service = ContextUtil.getInstance().getSampleTypeService();
		sampleType = service.getSampleTypeById(sampleType.getSampleTypeId());
		if(null != sampleType){
			service.deleteSampleType(sampleType);
		}
		return getSampleTypeList(mapping,form,request,response);
	}
}
